package com.wangyang.stock.business.services;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.wangyang.stock.business.IStorehouseService;
import com.wangyang.stock.dao.IDao;
import com.wangyang.stock.po.Employee;
import com.wangyang.stock.po.Storehouse;
import com.wangyang.stock.vo.StorehouseVo;

public class StorehouseServiceImp implements IStorehouseService {
	private IDao dao;

	public IDao getDao() {
		return dao;
	}

	public void setDao(IDao dao) {
		this.dao = dao;
	}

	public List selectStorehouse(StorehouseVo storehouseVo) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer(
				"from Storehouse storehouse where 1=1 ");
		List list = dao.select(hql.toString());
		List volist = new ArrayList();
		for (int i = 0; i < list.size(); i++) {
			Storehouse sh = (Storehouse) list.get(i);
			StorehouseVo shVo = new StorehouseVo();
			BeanUtils.copyProperties(sh, shVo);
			shVo.setEmployeeId(sh.getEmployee().getEmployeeId());
			shVo.setEmployeeName(sh.getEmployee().getEmployeeName());
			volist.add(shVo);
		}
		return volist;
	}

	public boolean createStorehouse(StorehouseVo storehouseVo) {
		// TODO Auto-generated method stub
		Storehouse storehouse = new Storehouse();
		BeanUtils.copyProperties(storehouseVo, storehouse);
		storehouse.setEmployee(new Employee(storehouseVo.getEmployeeId()));
		return dao.create(storehouse);
	}

	public boolean deleteStorehouse(StorehouseVo storehouseVo) {
		// TODO Auto-generated method stub
		Storehouse storehouse = new Storehouse();
		BeanUtils.copyProperties(storehouseVo, storehouse);
		storehouse.setEmployee(new Employee(storehouseVo.getEmployeeId()));
		return dao.delete(storehouse);
	}

	public boolean updateStorehouse(StorehouseVo storehouseVo) {
		// TODO Auto-generated method stub
		Storehouse storehouse = new Storehouse();
		BeanUtils.copyProperties(storehouseVo, storehouse);
		storehouse.setEmployee(new Employee(storehouseVo.getEmployeeId()));
		
		return dao.update(storehouse);
	}

}
